<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<base href="<%=basePath%>">

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>忘记密码</title>


<jsp:include page="../common/common.jsp"></jsp:include>


<link rel="stylesheet"
	href="<%=request.getContextPath()%>/resources/js/mybootstrap/css/bootstrap.css" />
<link
	href="<%=request.getContextPath()%>/resources/css/system/index/common.css"
	rel="stylesheet"></link>
<link
	href="<%=request.getContextPath()%>/resources/css/system/index/login.css"
	rel="stylesheet"></link>



</head>

<body class="client-body">
	<jsp:include page="forgetPassHead.jsp"></jsp:include>

	<div class="client-content fp-content">
		<form class="fp-form" action="">
			<div class="fp-formTitle">密码找回</div>

			<div class="fp-formContent">
				<div class="fp-formHead">1、 验证手机号</div>

				<div class="list-tr">
					<input type="text" name="phone" id="phone" placeholder="手机号" />
				</div>
				<div class="list-tr2">
					<input type="text" name="VBR" id="VBR" placeholder="动态码" />
					<a class="a-white btn2" href="javascript:;" id="mobileCode">获取动态码</a>
				</div>

				<div class="foot-box btn2 fp-formBtn" id="forgetNext">
					<a class="foot-butten a-white" href="javascript:;">下一步</a>
				</div>

				<div class="error-resgister">
					<span id="errorContent"></span>
					<!-- 错误提示 -->
				</div>
			</div>
		</form>
	</div>
	<script
		src="<%=request.getContextPath()%>/resources/js/jquery/1.12.4/jquery.min.js"></script>
	<script
		src="<%=request.getContextPath()%>/resources/js/system/index/Cookies.js"></script>
	<script type="text/javascript">
var timer;
var t=121;
var name="resetpwd_phoneno";

var re = /^(13[0-9]|14[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$/;

$(document).ready(function(){
	infoSure();
	$("#mobileCode").bind("click.mobileCode",function(){
			$.ajax({
				type:'post',
				url:CONTEXT_PATH+'/before/register/uniqueVerify',
				data:{"name":name,"value":$("#phone").val()},
				success:function(data){
					if(data.flag==false){
						$("#phone").val('');
						$("#errorContent").text(data.message);
					}else{
						getVerifyCode();
					}
				}
			});
	});
});

function code(){
	t--;
	$("#mobileCode").text(t);
	if(t==0){
		timer=window.clearInterval(timer);
		$("#mobileCode").text("获取动态码");
		t=121;
  		$("#mobileCode").bind("click.mobileCode",function(){ 
			getVerifyCode();  
	    });
	}
}

function infoSure(){
	$("#forgetNext").click(function(){
			
	var phone=$("#phone").val();
	var dynamiccode=$("#VBR").val();
		
	if(phone==""||dynamiccode==""){
		$(".error-resgister").css("display","block");
		$("#errorContent").text("您所填信息不完整！");
	}else if(!re.test(phone)){
		$(".error-resgister").css("display","block");
		$("#errorContent").text("您输入的手机号格式不正确！");
	}else{
		$("#errorContent").text("");
		$.ajax({
			type:'post',
    		url:CONTEXT_PATH+'before/register/dynamiccodeVerify',
   			data:{'dynamiccode':$('#VBR').val(),phone:$('#phone').val()},
     		success:function(data){           
           		if(data.flag==false){
               		RemainTime();
             		alert(data.message); 
           		}else{
          			window.location.href='<%=request.getContextPath() %>/before/forgetPass2?phone='+$('#phone').val();
         		}
        	}
		});
	}
	});
}

function getVerifyCode(){
  	$("#errorContent").text(""); 
	if(verifyPhone()==false){
  		return false;
    }
   	$("#mobileCode").unbind("click.mobileCode");
 		timer=setInterval("code()",1000);
 		Cookies.set("isget","true","s120");//2分钟后才可以重新获取验证码防止短信轰炸
  		$.ajax({
   			type:'post',
   			url:CONTEXT_PATH+'before/register/getVerifyCode',
        	data:{phone:$('#phone').val()},
      		success:function(data){
   				alert(data.message);
    		}
    	});   
}

function verifyPhone(){
	if($("#phone").val()=="" || $("#phone").val()==null){
		$("#errorContent").text("手机号不能为空！");
		return false;
	}
	 
	if (!re.test($("#phone").val())){
  		$("#errorContent").text("手机号格式不正确！");
 		return false;
	} 
	return true;
}
</script>


</body>
</html>
